package com.mipo.service;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.mipo.dao.imp.EmployeeDAO;
import com.mipo.dao.imp.EmployeeDAOImp;
import com.mipo.vo.Employee;

public class LoginService extends HttpServlet {

	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String code = request.getParameter("codeName");
		
		HttpSession session = request.getSession();
		String sessionCode = session.getAttribute("codes").toString();
		if (sessionCode.toUpperCase().equals(code.toUpperCase())) {
			String loginName = request.getParameter("loginName");
			String password = request.getParameter("password");
			EmployeeDAO dao = new EmployeeDAOImp();
			try {
				Employee emp = dao.query(loginName, password);
				session.setAttribute("tzx", emp);
				response.sendRedirect("inTake.shtml");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}else{
			response.sendRedirect("login.jsp");
		}
	}

}
